package com.ynet.middleground.riskmanage.service.impl.qichacha;

import java.util.List;

import javax.validation.Valid;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import com.ynet.middleground.riskmanage.service.impl.GenericService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import com.google.common.base.Throwables;
import com.ynet.core.common.ServiceResult;
import com.ynet.core.exception.BusinessException;
import com.ynet.core.log.IfpLogger;
import com.ynet.middleground.riskmanage.bean.qichacha.personcorrelation.*;
import com.ynet.middleground.riskmanage.dto.qichacha.personcorrelation.*;
import com.ynet.middleground.riskmanage.model.qichacha.PersonCorrelationModel;
import com.ynet.middleground.riskmanage.service.qichacha.PersonCorrelationService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

/**
 * @ClassName PersonCorrelationServiceImpl
 * @Description 企查查人员相关接口实现类
 * @Author zhangyongbin
 * @Date 2020/8/7 17:06
 * @Version 1.0
 */
@Produces({MediaType.APPLICATION_JSON + "; " + "charset=UTF-8"})
@Consumes({MediaType.APPLICATION_JSON + "; " + "charset=UTF-8"})
@Api(value = "企查查人员相关接口服务", tags = {"企查查人员相关接口服务"})
@Path("qcc")
@Service(timeout = 6000, version = "0.0.1")
public class PersonCorrelationServiceImpl implements PersonCorrelationService, GenericService {

    @Autowired
    PersonCorrelationModel personCorrelationModel;

    /**
     * @see com.ynet.middleground.riskmanage.service.qichacha.PersonCorrelationService
     **/
    @POST
    @Path("holding")
    @ApiOperation(value = "董监高控制企业核查,每页条目数最大不超过20条", notes = "董监高控制企业核查,每页条目数最大不超过20条")
    @ApiImplicitParam(name = "requestObj", dataType = "PersonHoldingCompanyReq", paramType = "body", required = true)
    @Override
    public ServiceResult<PersonHoldingInfoDTO>
        queryPersonHoldingCompanyInfo(@Valid PersonHoldingCompanyReq personHoldingCompanyReq) {

        ServiceResult<PersonHoldingInfoDTO> result = new ServiceResult<>();

        try {
            result.setResult(personCorrelationModel.queryPersonHoldingInfo(personHoldingCompanyReq));
        } catch (BusinessException be) {
            result.setError(be.getCode(), be.getMessage());
        } catch (Exception e) {
            IfpLogger.error(Thread.currentThread().getStackTrace()[1].getMethodName(), "董监高控制企业核查服务异常, case: {}",
                Throwables.getStackTraceAsString(e));
            result.setError("ECRM0000", "服务异常，请联系系统管理员");
        }

        result.setPagerInfo(personHoldingCompanyReq.getPagerInfo());
        return result;

        // 1.请求参数

        // 2.调用服务

        // 3.解析返回数据

        // 4.记录日志 ---切面
    }

    // update by liwq on 2021-1-4 start, “个人自身风险条目数” 服务已合并到“个人自身风险扫描”服务
    /*@POST
    @Path("riskcount")
    @ApiOperation(value = "个人自身风险条目数", notes = "个人自身风险条目数")
    @ApiImplicitParam(name = "requestObj", dataType = "PersonRiskCountReq", paramType = "body", required = true)
    @Override
    public ServiceResult<PersonRiskCountDTO> getPersonalRiskCountInfo(PersonRiskCountReq req) {
        ServiceResult<PersonRiskCountDTO> result = new ServiceResult<>();
    
        try {
            result.setResult(personCorrelationModel.getPersonalRiskCountInfo(req));
        } catch (BusinessException be) {
            result.setError(be.getCode(), be.getMessage());
        } catch (Exception e) {
            IfpLogger.error(Thread.currentThread().getStackTrace()[1].getMethodName(), "个人自身风险条目数服务异常, case: {}",
                    Throwables.getStackTraceAsString(e));
            result.setError("ECRM0000", "服务异常，请联系系统管理员");
        }
        return result;
    }*/
    // update by liwq on 2021-1-4 end, “个人自身风险条目数” 服务已合并到“个人自身风险扫描”服务

    @POST
    @Path("riskcheck")
    @ApiOperation(value = "个人自身风险扫描", notes = "个人自身风险扫描")
    @ApiImplicitParam(name = "requestObj", dataType = "PersonRiskCountInfoReq", paramType = "body", required = true)
    @Override
    public ServiceResult<PersonRiskCheckInfoDTO> getPersonRiskCountCheckInfo(PersonRiskCountInfoReq req) {
        ServiceResult<PersonRiskCheckInfoDTO> result = new ServiceResult<>();

        try {
            result.setResult(personCorrelationModel.getPersonRiskCountCheckInfo(req));
        } catch (BusinessException be) {
            result.setError(be.getCode(), be.getMessage());
        } catch (Exception e) {
            IfpLogger.error(Thread.currentThread().getStackTrace()[1].getMethodName(), "个人自身风险扫描服务异常, case: {}",
                Throwables.getStackTraceAsString(e));
            result.setError("ECRM0000", "服务异常，请联系系统管理员");
        }
        return result;
    }

    @POST
    @Path("sxcheck")
    @ApiOperation(value = "个人自身风险-失信被执行核查", notes = "个人自身风险-失信被执行核查")
    @ApiImplicitParam(name = "requestObj", dataType = "PersonRiskInfoReq", paramType = "body", required = true)
    @Override
    public ServiceResult<PersonSXCheckInfoDTO> getPersonSXCheckList(@Valid PersonRiskInfoReq req) {
        ServiceResult<PersonSXCheckInfoDTO> result = new ServiceResult<>();

        try {
            result.setResult(personCorrelationModel.getPersonSXCheckList(req));
        } catch (BusinessException be) {
            result.setError(be.getCode(), be.getMessage());
        } catch (Exception e) {
            IfpLogger.error(Thread.currentThread().getStackTrace()[1].getMethodName(), "个人自身风险-失信被执行核查服务异常, case: {}",
                Throwables.getStackTraceAsString(e));
            result.setError("ECRM0000", "服务异常，请联系系统管理员");
        }
        result.setPagerInfo(req.getPagerInfo());

        return result;
    }

    @POST
    @Path("zxcheck")
    @ApiOperation(value = "个人自身风险-被执行人核查", notes = "个人自身风险-被执行人核查")
    @ApiImplicitParam(name = "requestObj", dataType = "PersonRiskInfoReq", paramType = "body", required = true)
    @Override
    public ServiceResult<PersonZXCheckInfoDTO> getPersonZXCheckList(@Valid PersonRiskInfoReq req) {
        ServiceResult<PersonZXCheckInfoDTO> result = new ServiceResult<>();

        try {
            result.setResult(personCorrelationModel.getPersonZXCheckList(req));
        } catch (BusinessException be) {
            result.setError(be.getCode(), be.getMessage());
        } catch (Exception e) {
            IfpLogger.error(Thread.currentThread().getStackTrace()[1].getMethodName(), "个人自身风险-被执行人核查服务异常, case: {}",
                Throwables.getStackTraceAsString(e));
            result.setError("ECRM0000", "服务异常，请联系系统管理员");
        }
        result.setPagerInfo(req.getPagerInfo());

        return result;
    }

    @POST
    @Path("sumptuaryCheck")
    @ApiOperation(value = "个人自身风险-限制高消费核查", notes = "个人自身风险-限制高消费核查")
    @ApiImplicitParam(name = "requestObj", dataType = "PersonRiskInfoReq", paramType = "body", required = true)
    @Override
    public ServiceResult<PersonSumptuaryCheckInfoDTO> getPersonSumptuaryCheckList(@Valid PersonRiskInfoReq req) {
        ServiceResult<PersonSumptuaryCheckInfoDTO> result = new ServiceResult<>();

        try {
            result.setResult(personCorrelationModel.getPersonSumptuaryCheckList(req));
        } catch (BusinessException be) {
            result.setError(be.getCode(), be.getMessage());
        } catch (Exception e) {
            IfpLogger.error(Thread.currentThread().getStackTrace()[1].getMethodName(), "个人自身风险-限制高消费核查服务异常, case: {}",
                Throwables.getStackTraceAsString(e));
            result.setError("ECRM0000", "服务异常，请联系系统管理员");
        }
        result.setPagerInfo(req.getPagerInfo());

        return result;
    }

//    @POST
//    @Path("dishonestInfoCheck")
//    @ApiOperation(value = "人员相关-个人失信信息核查", notes = "人员相关-个人失信信息核查")
//    @ApiImplicitParam(name = "requestObj", dataType = "PersonDishonestInfoReq", paramType = "body", required = true)
//    @Override
//    public ServiceResult<PersonDishonestInfoDTO> getPersonDishonestInfoList(@Valid PersonDishonestInfoReq req) {
//        ServiceResult<PersonDishonestInfoDTO> result = new ServiceResult<>();
//        try {
//            result.setResult(personCorrelationModel.getPersonDishonestInfoList(req));
//        } catch (BusinessException be) {
//            result.setError(be.getCode(), be.getMessage());
//        } catch (Exception e) {
//            IfpLogger.error(Thread.currentThread().getStackTrace()[1].getMethodName(), "人员相关-个人失信信息核查服务异常, case: {}",
//                Throwables.getStackTraceAsString(e));
//            result.setError("ECRM0000", "服务异常，请联系系统管理员");
//        }
//        result.setPagerInfo(req.getPagerInfo());
//        return result;
//    }

    @POST
    @Path("executedInfoCheck")
    @ApiOperation(value = "人员相关-个人被执行人核查", notes = "人员相关-个人被执行人核查")
    @ApiImplicitParam(name = "requestObj", dataType = "PersonExecutedInfoDTO", paramType = "body", required = true)
    @Override
    public ServiceResult<PersonExecutedInfoDTO> getPersonExecutedInfoList(@Valid PersonExecutedInfoReq req) {
        ServiceResult<PersonExecutedInfoDTO> result = new ServiceResult<>();
        try {
            result.setResult(personCorrelationModel.getPersonExecutedInfoList(req));
        } catch (BusinessException be) {
            result.setError(be.getCode(), be.getMessage());
        } catch (Exception e) {
            IfpLogger.error(Thread.currentThread().getStackTrace()[1].getMethodName(), "人员相关-个人失信信息核查服务异常, case: {}",
                Throwables.getStackTraceAsString(e));
            result.setError("ECRM0000", "服务异常，请联系系统管理员");
        }
        result.setPagerInfo(req.getPagerInfo());
        return result;
    }
}
